Skip to content

port RandomZoomOut from detection references to prototype transforms #5551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 14, 2022

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Mar 4, 2022

Addresses #5542.

Example script to be run in references/detection:

import torch

from torchvision.prototype import features, transforms as prototype_transforms
from torchvision.transforms.functional import pil_to_tensor, to_pil_image
from torchvision.utils import draw_bounding_boxes

import transforms as reference_transforms
from train import get_dataset

seed = 1234


def draw(sample):
    image, targets = sample
    annotated_image = draw_bounding_boxes(image, targets["boxes"], width=4)
    to_pil_image(annotated_image).show()


dataset, _ = get_dataset(
    name="coco",
    image_set="train",
    transform=None,
    data_path=...,
)

fill = [123.0, 117.0, 104.0]

reference_sample = (
    pil_to_tensor(dataset[0][0]),
    dict(boxes=dataset[0][1]["boxes"]),
)
prototype_sample = (
    features.Image(reference_sample[0].clone()),
    dict(
        boxes=features.BoundingBox(
            reference_sample[1]["boxes"].clone(),
            format="xyxy",
            image_size=reference_sample[0].shape[-2:],
        )
    ),
)


reference_transform = reference_transforms.RandomZoomOut(fill=fill, p=1.0)
torch.manual_seed(seed)
reference_transformed_sample = reference_transform(*reference_sample)
draw(reference_transformed_sample)

prototype_transform = prototype_transforms.RandomZoomOut(fill=fill, p=1.0)
torch.manual_seed(seed)
prototype_transformed_sample = prototype_transform(prototype_sample)
draw(prototype_transformed_sample)

torch.testing.assert_close(prototype_transformed_sample, reference_transformed_sample, atol=0, rtol=0)

example

@facebook-github-bot
Copy link

facebook-github-bot commented Mar 4, 2022

💊 CI failures summary and remediations

As of commit 09f5191 (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

1 failure not recognized by patterns:

Job Step Action
CircleCI cmake_macos_cpu curl -o conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh conda.sh -b
source $HOME/miniconda3/bin/activate
conda install -yq conda-build cmake
packaging/build_cmake.sh
🔁 rerun

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmeier Thanks! Overall looks good, but I got some comments. Let me know your thoughts

@pmeier pmeier requested a review from datumbox March 14, 2022 08:53
Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment for a potential bug. Other than that it looks good.

@pmeier pmeier requested a review from datumbox March 14, 2022 12:31
Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@pmeier pmeier merged commit 05b5e8c into pytorch:main Mar 14, 2022
@pmeier pmeier deleted the transforms/zoom-out branch March 14, 2022 13:17
@pmeier pmeier mentioned this pull request Mar 14, 2022
24 tasks
facebook-github-bot pushed a commit that referenced this pull request Mar 15, 2022
…ansforms (#5551)

Summary:
* port RandomZoomOut from detection references to prototype transforms

* copy by default

* move padding parsing to stable API

* merge zoom out kernels into transform

* lint

* fix filling if no padding was done

* resolve todo

Reviewed By: vmoens

Differential Revision: D34878967

fbshipit-source-id: 973e8c088d38c0d2849a557b3a3d83e98dc8bf63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants